import request from '@/utils/request'

// 获取验证码
export const timeOuts = mobile => request.get(`sms/codes/${mobile}`)
// 登录请求
export const gogin = data => request.post('authorizations', data)

// 获取头部列表
export const getChannels = () => request.get('channels')

// 获取首页内容
export const HomeDetails = params => request.get('articles', { params })

// 获取文章详情
export const detailList = id => request.get(`articles/${id}`)

// 获取用户个人资料
export const getUserProfile = () => request.get('/user/profile')

// // 编辑用户个人资料
// export const upUserPopup = data => request.patch('/user/photo', data)

// 关注用户
// export const followings = () => request.post('/user/followings')

// 获取评论或评论回复
export const Artcomments = params => request.get('/comments', { params })

// 获取用户频道
export const UserChannel = () => request.get('/user/channels')

// 用户关注
export const followAuthor = (authorId, isFollow) => {
  if (isFollow) {
    return request({
      url: '/user/followings',
      method: 'post',
      data: { target: authorId }
    })
  } else {
    return request({
      url: '/user/followings/' + authorId,
      method: 'delete'
    })
  }
}

// 收藏
export const collAuthor = (authorId, isFollow) => {
  if (isFollow) {
    return request({
      url: '/article/collections',
      method: 'post',
      data: { target: authorId }
    })
  } else {
    return request({
      url: '/article/collections/' + authorId,
      method: 'delete'
    })
  }
}

// 文章点赞
export const likeArticle = (articleId, isLike) => {
  if (isLike) {
    return request({
      url: '/article/likings',
      method: 'post',
      data: { target: articleId }
    })
  } else {
    return request({
      url: '/article/likings/' + articleId,
      method: 'delete'
    })
  }
}
